package cn.itcast.com.network.tcp.demo02;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;

public class Server {
    public static void main(String[] args) throws IOException {
        //创建socket对象,这个指定的端口号ip都是本身的
        ServerSocket serversocket = new ServerSocket(8282);
        //使用accept，接受请求，并建立连接
        //阻塞
        Socket socket = serversocket.accept();
        //正式开始数据传输
        InputStream inputStream = socket.getInputStream();

        byte[] bytes = new byte[1024];
        inputStream.read(bytes);
        String s = new String(bytes);
        System.out.println(s);
        //获得请求服务的客户端的端口和ip
        System.out.println(socket.getPort());
        System.out.println(socket.getInetAddress());
    }
}
